package com.example.springboot_vue.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_vue.common.PageDto;
import com.example.springboot_vue.entity.StorageEntity;
import com.example.springboot_vue.mapper.StorageMapper;
import com.example.springboot_vue.service.StorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sgp
 * @since 2024-07-19
 */
@Service
public class StorageServiceImpl extends ServiceImpl<StorageMapper, StorageEntity> implements StorageService {

    @Autowired
    private StorageMapper storageMapper;
    @Override
    public PageDto<StorageEntity> selectAll(StorageEntity storageEntity) {
        QueryWrapper<StorageEntity> queryWrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(storageEntity.getName())){
            queryWrapper.lambda().like(StorageEntity::getName,storageEntity.getName());
        }
        Page<StorageEntity> page = new Page<>(storageEntity.getPage(), storageEntity.getSize());
        Page<StorageEntity> selectPage = storageMapper.selectPage(page, queryWrapper);
        PageDto<StorageEntity> pageDto = new PageDto<>();
        pageDto.setTotal(selectPage.getTotal());
        pageDto.setList(selectPage.getRecords());
        return pageDto;
    }

}
